
/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package org.kallsonys.oms.ws.productservices;

import java.util.logging.Logger;

import org.kallsonnys.oms.dto.ProductDTO;
import org.kallsonnys.oms.dto.TableResultDTO;
import org.kallsonnys.oms.services.products.ProductsRemote;
import org.kallsonys.oms.commons.locator.ServiceLocator;
import org.kallsonys.oms.ws.mapper.WSMapper;

import com.integration.kallsonys.kallsonysschema.types.PagingDto;
import com.integration.kallsonys.kallsonysschema.types.Product;
import com.integration.kallsonys.kallsonysschema.types.ProductDetailId;
import com.integration.kallsonys.kallsonysschema.types.ProductList;

/**
 * This class was generated by Apache CXF 2.6.3
 * 2013-10-24T00:33:16.627-05:00
 * Generated source version: 2.6.3
 * 
 */

@javax.jws.WebService(
                      serviceName = "ProductServices",
                      portName = "ProductServicesSOAP",
                      targetNamespace = "http://ws.oms.kallsonys.org/productservices",
                      wsdlLocation = "file:/Users/macbook/Documents/BUS-KallsonnysOMS-WS/war/WEB-INF/wsdl/productServices.wsdl",
                      endpointInterface = "org.kallsonys.oms.ws.productservices.ProductServices")
public class ProductServicesImpl implements ProductServices {

    private static final Logger logger = Logger.getLogger(ProductServicesImpl.class.getName());

	public ProductList getProducts(PagingDto pagingDto)
			throws ProductFault {
		try {
			
			logger.info("getProducts:Operation start");
			
        	ProductsRemote productsBeanRemote = ServiceLocator.getInstance().getRemoteObject("ProductsBean");
        	TableResultDTO<ProductDTO> productsList = productsBeanRemote.getProductsList(WSMapper.mapTableFilterDTO(pagingDto));
        	
        	ProductList productList = WSMapper.mapProductList(productsList.getResult());
        	
        	return productList;
			
		} catch (Exception e) {
			throw new ProductFault("OCURRIO UN ERROR GENERAL OBTENIENDO LOS PRODUCTOS", e);
		}finally{
			logger.info("getProducts:Operation finish");
		}
		
	}

	public Product getProductDetail(ProductDetailId getProductDetailRequest)
			throws GetProductDetailFault {
		try {

			logger.info("getProductDetail:Operation start");
			
			ProductsRemote productsBeanRemote = ServiceLocator.getInstance().getRemoteObject("ProductsBean");
			ProductDTO productDTO = productsBeanRemote.getProductDetail(Long.parseLong(getProductDetailRequest.getId()));
			
			return WSMapper.mapProduct(productDTO);

		} catch (Exception e) {
			throw new GetProductDetailFault("OCURRIO UN ERROR GENERAL AL OBTENER EL DETALLE DEL PRODUCTO", e);
		} finally {
			logger.info("getProductDetail:Operation finish");
		}
		
	}

}
